package cn.java78.springboot.myschool.ctrl;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author oldliu
 * @since 1.0
 */
@Controller
@RequestMapping("admin")
public class AdminController {

    //private AdminService adminService= SpringUtil.getBean(AdminService.class);
//    @Resource
//    private AdminService adminService;

    @Value("3")
    private int loginCount;
    //request.getParameter("uname")
    @RequestMapping("login")
    public String login(@RequestParam(name = "loginname",required = true) String uname, @RequestParam(name = "upass",required = true)  String upass, HttpServletRequest req){
        ModelAndView mv=new ModelAndView();
        if("admin".equals(uname)&&"123".equals(upass))
        {
            req.getSession().setAttribute("loginuser",uname);
            return "/welcome.jsp";
        }

        req.setAttribute("msg","错误的用户名或者密码！");
        return "/login.jsp";
    }
    @PostMapping("reg")
    public String reg(Model m){
        //>>>m.addAttribute( new String("sss"));
        m.addAttribute("sss","s");
        return "/regok.jsp";
    }
}
